package b.l.a;

import android.os.Bundle;
import android.os.Parcelable;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.Fragment.SavedState;
import b.n.d.b;
import b.u.a.a;
import com.liuzh.deviceinfo.MainActivity;
import java.util.ArrayList;
import java.util.Objects;

/* compiled from: FragmentStatePagerAdapter */
public abstract class o extends a {
    public final h c;
    public final int d;
    public p e = null;
    public ArrayList<SavedState> f = new ArrayList();
    public ArrayList<Fragment> g = new ArrayList();
    public Fragment h = null;

    public o(h hVar, int i) {
        this.c = hVar;
        this.d = i;
    }

    /* JADX WARNING: Removed duplicated region for block: B:23:? A:{SYNTHETIC, RETURN} */
    /* JADX WARNING: Removed duplicated region for block: B:20:0x0069  */
    public void a(android.view.ViewGroup r4, int r5, java.lang.Object r6) {
        /*
        r3 = this;
        r6 = (androidx.fragment.app.Fragment) r6;
        r4 = r3.e;
        if (r4 != 0) goto L_0x0014;
    L_0x0006:
        r4 = r3.c;
        r4 = (b.l.a.i) r4;
        java.util.Objects.requireNonNull(r4);
        r0 = new b.l.a.a;
        r0.m5085init(r4);
        r3.e = r0;
    L_0x0014:
        r4 = r3.f;
        r4 = r4.size();
        r0 = 0;
        if (r4 > r5) goto L_0x0023;
    L_0x001d:
        r4 = r3.f;
        r4.add(r0);
        goto L_0x0014;
    L_0x0023:
        r4 = r3.f;
        r1 = r6.z();
        if (r1 == 0) goto L_0x0057;
    L_0x002b:
        r1 = r3.c;
        r1 = (b.l.a.i) r1;
        java.util.Objects.requireNonNull(r1);
        r2 = r6.r;
        if (r2 != r1) goto L_0x0046;
    L_0x0036:
        r2 = r6.a;
        if (r2 <= 0) goto L_0x0057;
    L_0x003a:
        r1 = r1.q0(r6);
        if (r1 == 0) goto L_0x0057;
    L_0x0040:
        r2 = new androidx.fragment.app.Fragment$SavedState;
        r2.m165init(r1);
        goto L_0x0058;
    L_0x0046:
        r4 = new java.lang.IllegalStateException;
        r5 = "Fragment ";
        r2 = " is not currently in the FragmentManager";
        r5 = c.b.a.a.a.C(r5, r6, r2);
        r4.<init>(r5);
        r1.w0(r4);
        throw r0;
    L_0x0057:
        r2 = r0;
    L_0x0058:
        r4.set(r5, r2);
        r4 = r3.g;
        r4.set(r5, r0);
        r4 = r3.e;
        r4.g(r6);
        r4 = r3.h;
        if (r6 != r4) goto L_0x006b;
    L_0x0069:
        r3.h = r0;
    L_0x006b:
        return;
        */
        throw new UnsupportedOperationException("Method not decompiled: b.l.a.o.a(android.view.ViewGroup, int, java.lang.Object):void");
    }

    public void b(ViewGroup viewGroup) {
        p pVar = this.e;
        if (pVar != null) {
            pVar.d();
            this.e = null;
        }
    }

    public Object f(ViewGroup viewGroup, int i) {
        Fragment fragment;
        if (this.g.size() > i) {
            fragment = (Fragment) this.g.get(i);
            if (fragment != null) {
                return fragment;
            }
        }
        if (this.e == null) {
            i iVar = (i) this.c;
            Objects.requireNonNull(iVar);
            this.e = new a(iVar);
        }
        fragment = (Fragment) MainActivity.this.s.get(i);
        if (this.f.size() > i) {
            SavedState savedState = (SavedState) this.f.get(i);
            if (savedState != null) {
                if (fragment.r == null) {
                    Bundle bundle = savedState.a;
                    if (bundle == null) {
                        bundle = null;
                    }
                    fragment.b = bundle;
                } else {
                    throw new IllegalStateException("Fragment already added");
                }
            }
        }
        while (this.g.size() <= i) {
            this.g.add(null);
        }
        fragment.g0(false);
        if (this.d == 0) {
            fragment.k0(false);
        }
        this.g.set(i, fragment);
        this.e.f(viewGroup.getId(), fragment, null, 1);
        if (this.d == 1) {
            this.e.h(fragment, b.STARTED);
        }
        return fragment;
    }

    public boolean g(View view, Object obj) {
        return ((Fragment) obj).G == view;
    }

    public void i(Parcelable parcelable, ClassLoader classLoader) {
        if (parcelable != null) {
            Bundle bundle = (Bundle) parcelable;
            bundle.setClassLoader(classLoader);
            Parcelable[] parcelableArray = bundle.getParcelableArray("states");
            this.f.clear();
            this.g.clear();
            if (parcelableArray != null) {
                for (Parcelable parcelable2 : parcelableArray) {
                    this.f.add((SavedState) parcelable2);
                }
            }
            for (String str : bundle.keySet()) {
                if (str.startsWith("f")) {
                    int parseInt = Integer.parseInt(str.substring(1));
                    Fragment c = this.c.c(bundle, str);
                    if (c != null) {
                        while (this.g.size() <= parseInt) {
                            this.g.add(null);
                        }
                        c.g0(false);
                        this.g.set(parseInt, c);
                    } else {
                        StringBuilder stringBuilder = new StringBuilder();
                        stringBuilder.append("Bad fragment at key ");
                        stringBuilder.append(str);
                        Log.w("FragmentStatePagerAdapt", stringBuilder.toString());
                    }
                }
            }
        }
    }

    public Parcelable j() {
        Bundle bundle;
        if (this.f.size() > 0) {
            bundle = new Bundle();
            SavedState[] savedStateArr = new SavedState[this.f.size()];
            this.f.toArray(savedStateArr);
            bundle.putParcelableArray("states", savedStateArr);
        } else {
            bundle = null;
        }
        for (int i = 0; i < this.g.size(); i++) {
            Fragment fragment = (Fragment) this.g.get(i);
            if (fragment != null && fragment.z()) {
                if (bundle == null) {
                    bundle = new Bundle();
                }
                this.c.f(bundle, c.b.a.a.a.A("f", i), fragment);
            }
        }
        return bundle;
    }

    public void k(ViewGroup viewGroup, int i, Object obj) {
        Fragment fragment = (Fragment) obj;
        Fragment fragment2 = this.h;
        if (fragment != fragment2) {
            i iVar;
            if (fragment2 != null) {
                fragment2.g0(false);
                if (this.d == 1) {
                    if (this.e == null) {
                        iVar = (i) this.c;
                        Objects.requireNonNull(iVar);
                        this.e = new a(iVar);
                    }
                    this.e.h(this.h, b.STARTED);
                } else {
                    this.h.k0(false);
                }
            }
            fragment.g0(true);
            if (this.d == 1) {
                if (this.e == null) {
                    iVar = (i) this.c;
                    Objects.requireNonNull(iVar);
                    this.e = new a(iVar);
                }
                this.e.h(fragment, b.RESUMED);
            } else {
                fragment.k0(true);
            }
            this.h = fragment;
        }
    }

    public void l(ViewGroup viewGroup) {
        if (viewGroup.getId() == -1) {
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append("ViewPager with adapter ");
            stringBuilder.append(this);
            stringBuilder.append(" requires a view id");
            throw new IllegalStateException(stringBuilder.toString());
        }
    }
}
